<template>
  <div class="business">
    <div class="items">
      <div
        class="item"
        v-for="(item,index) in supplierUsers"
        :key="index"
        :supplierId="item.supplierId"
        :supplierName="item.supplierName"
        @click="goHome($event)"
      >
        <img src="../assets/images/ada.jpg" alt />
        <p>{{item.supplierName}}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { setCookie } from "../unit/cookie";
export default {
  name: "select-business",
  data() {
    return {
      supplierUsers: []
    };
  },
  created() {
    this.getSup();
  },
  methods: {
    getSup() {
      let that = this;
      that.supplierUsers = this.$store.state.common.supplierUsers;
    },
    // 跳转
    goHome(event) {
      let that = this;
      let e = event.currentTarget;
      let url = "ac/api/v1/reserve/createPlatformUser";
      let param = {
        userTel: Number(this.$store.state.common.mobile),
        code: Number(this.$store.state.common.code),
        uid: 3323,
        isUpdate: true,
        supplierId: e.getAttribute("supplierId")
      };
      that.$ajax.post(url, that.qs.stringify(param)).then(res => {
        //登陆成功
        if (res.status == 200) {
          // 保存门店id和门店名称，后边要用
          that.$store.commit("SetSupplierName", e.getAttribute("supplierName"));
          that.$store.commit("SetSupplierId", e.getAttribute("supplierId"));
          // 7天登陆信息
          setCookie("expireTime", res.data.expireTime, 7);
          setCookie("jwtToken", res.data.jwtToken, 7);
          setCookie("userId", res.data.userId, 7);
          that.$router.push("/home");
        }
      });
    }
  }
};
</script>

<style scoped>
.items {
  width: 100%;
  display: flex;
  flex-flow: column;
  justify-content: center;
}
.items .item {
  padding-top: 40px;
  text-align: center;
}
.items .item img {
  width: 700px;
  height: 700px;
}
.items .item p {
  font-size: 80px;
  margin-top: 30px;
}
</style>